<?php
/**
 * 门锁/网管/房间关系管理类
 *
 * @auther 大耳牛
 * 2016-12-31
 **/
namespace Home\Model;
use Think\Model;
class LockopenModel extends Model{
	//定义表名称
	protected $tableName = 'lockopen_log';
	
	/**
	 * 获取网管列表总数
	 *
	 **/
	public function getLockopenLogListCount($where){
		return $this->where($where)->count();
	}
	
	/**
	 * 获取开门日志
	 *
	 **/
	public function getLockopenLogList($page, $where){
		return $this->alias('oplog')
					->join('left join momoda_lock as slock on oplog.lock_no = slock.cmd_id AND oplog.`network_id` = slock.`network_id`')
					->join('left join momoda_room as room on slock.room_id = room.room_id')
					->field('oplog.*, room.room_number')
					->where($where)->order('oplog.j_id desc')->page($page, C('PAGE_SIZE'))->select();
	}
	
	/**
	 * 获取所有开门日志
	 *
	 **/
	public function getLockopenLogListAll($where){
		return $this->alias('oplog')
					->join('left join momoda_lock as slock on oplog.lock_no = slock.cmd_id AND oplog.`network_id` = slock.`network_id`')
					->join('left join momoda_room as room on slock.room_id = room.room_id')
					->field('oplog.*, room.room_number')
					->where($where)
					->order('oplog.j_id desc')
					->select();
	}
	
	/**
	 * 保存信息
	 *
	 **/
	public function addLockopenLogAll($data){
		return $this->addAll($data);
	}
	
	/**
	 * 根据网管号获取该网管下最大的记录ID
	 * @param string $network_nums
	 *
	 **/
	public function getMaxJidByNetworkNums($network_nums){
		return $this->where(array('user_num' => $network_nums))->max('j_id');
	}
}